﻿using ESRI.ArcGIS.Carto;
using Inovout.Gis.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System;
using Inovout.Gis;

namespace Inovout.ArcGis
{
    internal static class ArcGisHelper
    {

        internal static Gis.ILayerInfo CreateLayer(IGroupLayerInfo owner, ILayer arcLayer)
        {
            if (arcLayer is IFeatureLayer)
            {
                return LayerFactory.CreateLayer(new FeatureLayerInfo(arcLayer as IFeatureLayer) { Owner = owner });
            }
            else if (arcLayer is IGroupLayer)
            {
                return LayerFactory.CreateLayer(new GroupLayerInfo(arcLayer as IGroupLayer) { Owner = owner });
            }
            else if (arcLayer is ITopologyLayer)
            {
                //拓朴图，用于检查
                return new TopologyLayerInfo(arcLayer as TopologyLayer) { Owner = owner };
            }
            else
            {
                throw new System.NotSupportedException("Esri.ILayer can not be Converted To LayerInfo");
            }
        }

        internal static IGeometryInfo CreateGeometry(IGeometryLayerInfo geometryLayer, IFeature arcFeature)
        {
            switch (arcFeature.Shape.GeometryType)
            {
                //case esriGeometryType.esriGeometryPolyline:
                //    return GeometryFactory.CreateGeometryElement(new PolyLineInfo(arcFeature) { Layer=geometryLayer});
                //case esriGeometryType.esriGeometryPoint:
                //    return GeometryFactory.CreateGeometryElement(new PointInfo(arcFeature) { Layer = geometryLayer });
                //case esriGeometryType.esriGeometryPolygon:
                //    return GeometryFactory.CreateGeometryElement(new PolygonInfo(arcFeature) { Layer = geometryLayer });
                default:
                    throw new NotImplementedException(arcFeature.Shape.GeometryType.ToString());
            }
        }
        internal static IGeometryInfo CreateArcGeometry(IGeometry arcGeometry)
        {
            switch (arcGeometry.GeometryType)
            {
                case esriGeometryType.esriGeometryPolyline:
                    return new PolyLineInfo(arcGeometry as IPolyline);
                case esriGeometryType.esriGeometryPoint:
                    return new PointInfo(arcGeometry as IPoint);
                case esriGeometryType.esriGeometryPolygon:
                    return new PolygonInfo(arcGeometry as IPolygon);
                default:
                    throw new NotImplementedException(arcGeometry.GeometryType.ToString());
            }
        }
    }

}
